unit FormHelpers;

interface

uses
 Forms,
 Buttons;

type
 PForm = ^TForm;
 TAfterCloseProcedure = procedure of object;

procedure BitBtnClick(AForm: PForm; const BitBtn: TBitBtn);
function IsFormClosed(AForm: PForm; AfterClose: TAfterCloseProcedure = nil): Boolean;

implementation

uses
 Controls,
 SysUtils;

procedure BitBtnClick(AForm: PForm; const BitBtn: TBitBtn);
begin
 if Assigned(AForm^) and Assigned(BitBtn) then
  begin
   if BitBtn.Owner=AForm^ then
    begin
     AForm^.ModalResult:=BitBtn.ModalResult;
     if not (fsModal in AForm^.FormState) then
       AForm^.Close;
    end;
  end;
end;

function IsFormClosed(AForm: PForm; AfterClose: TAfterCloseProcedure = nil): Boolean;
begin
 Result:=false;
 if Assigned(AForm^) and (not AForm^.Showing) then
  begin
   if AForm^.ModalResult=mrOK then
    begin
     if Assigned(AfterClose) then
       AfterClose;
    end;
   AForm^.Free;
   AForm^:=nil;
   Result:=true;
  end;
end;


end.
 